// component/singleSelectPop/singleSelectPop.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    popType: {
      type: String,
      value: ""
    },
    show: {
      type: Boolean,
      default: false
    },
    customArr: {
      type: Array,
      value: []
    },
    popTitle: {
      type: String,
      value: ""
    }
  },


  /**
   * 组件的初始数据
   */
  data: {
    result: null,
    //选择数据源
    dataArr: [],
    type: "",//单选类型
    title: "",//标题
    isScroll: false,
    //房屋装修arr:
    houseDecorations: [
      {
        value: "毛坯",
        label: "毛坯",
      },
      {
        value: "简装",
        label: "简装",
      },
      {
        value: "精装",
        label: "精装",
      },
      {
        value: "豪装",
        label: "豪装",
      }
    ],
    companyTypeArr: [
      {
        value: 1,
        label: "平台公司",
      },
      {
        value: 2,
        label: "资方公司",
      },
      {
        value: 3,
        label: "经纪公司",
      },
      {
        value: 4,
        label: "开发公司",
      }
    ],
    newRoles: [
      {
        label: "老板",
        value: 1
      },
      {
        label: "大区总",
        value: 2
      },
      {
        label: "店长",
        value: 3
      },
      {
        label: "总监",
        value: 4
      },
      {
        label: "经理",
        value: 4
      },
      {
        label: "经纪人",
        value: 4
      },
      {
        label: "员工",
        value: 4
      }
    ],
    //主推类型
    mainTypeArr: [
      {
        value: "公寓",
        label: "公寓",
      },
      {
        value: "住宅",
        label: "住宅",
      },
      {
        value: "别墅",
        label: "别墅",
      },
    ],
    //产权年限
    propertyYears: [
      {
        value: "70年",
        label: "70年"
      },
      {
        value: "40年",
        label: "40年"
      }
    ],
    //楼盘状态
    houseStatusArr: [
      {
        value: "在售",
        label: "在售"
      },
      {
        value: "待售",
        label: "待售"
      },
      {
        value: "招商",
        label: "招商"
      },
      {
        value: "停售",
        label: "停售"
      },
    ],
    bankArr: [
      {
        value: "中国人民银行",
        label: "中国人民银行"
      },
      {
        value: "农业银行",
        label: "农业银行"
      },
      {
        value: "工商银行",
        label: "工商银行"
      },
      {
        value: "建设银行",
        label: "建设银行"
      },
      {
        value: "交通银行",
        label: "交通银行"
      },
      {
        value: "招商银行",
        label: "招商银行"
      },
      {
        value: "邮政储蓄银行",
        label: "邮政储蓄银行"
      },
      {
        value: "兴业银行",
        label: "兴业银行"
      },
      {
        value: "民生银行",
        label: "民生银行"
      },
      {
        value: "中信银行",
        label: "中信银行"
      },
    ],










  },
  observers: {
    'popType': function (newValue) {
      this.setData({
        type: newValue
      })
      this.dataConfig();
    },
    'popTitle': function (newValue) {
      this.setData({
        title: newValue
      })
    }
  },
  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      this.setData({
        type: this.properties.popType
      })
      if (this.properties.customArr.length > 0) {
        this.setData({
          dataArr: this.properties.customArr
        })
      }
      if (this.data.dataArr.length > 0) {
        this.setData({
          result: this.data.dataArr[0]
        })
      }

    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    dataConfig() {
      //取配置数组
      switch (this.data.type) {
        case "decorationStatus":
          this.setData({
            dataArr: this.data.houseDecorations
          })
          break;
        case "propertyRights":
          this.setData({
            dataArr: this.data.propertyYears
          })
          break;
        case "saleStatus":
          this.setData({
            dataArr: this.data.houseStatusArr
          })
          break;
        case "mainType":
          this.setData({
            dataArr: this.data.mainTypeArr
          })
          break;
        case "companyType":
          this.setData({
            dataArr: this.data.companyTypeArr
          })
          break;
        case "bankName":
          this.setData({
            dataArr: this.data.bankArr
          })
          break;
        case "newRole":
          this.setData({
            dataArr: this.data.newRoles
          })
          break;

        default:
          break;

      }
      if (this.data.dataArr.length > 0) {
        this.setData({
          result: this.data.dataArr[0]
        })
      }

    },
    clickCenterPopupOverlay() {
      this.triggerEvent('popHide', { show: false });
    },
    //关闭弹窗
    popupCancel() {
      this.triggerEvent('popHide', { show: false });
    },
    //确认选择:
    popupTrue() {
      // this.triggerEvent('popSelect', { show: false, result: this.data.result, type: this.data.type })
      if (!this.data.isScroll) {
        this.triggerEvent('popSelect', { show: false, result: this.data.result, type: this.data.type })
      }
    },
    //最后的value:
    bindChange(e) {
      console.log("JJLog:新组建选中时:" + JSON.stringify(e));
      let index = e.detail.value[0];
      let value = this.data.dataArr[index];
      console.log("JJLog:选择到的值是:" + JSON.stringify(value));
      this.setData({
        result: value
      })
    },
    bindStartAction() {
      this.setData({
        isScroll: true
      })
    },
    bindEndAction() {
      this.setData({
        isScroll: false
      })
    },
  }
})
